package com.zdya.combatdocuments.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zdya.combatdocuments.entity.Document;
import com.zdya.combatdocuments.entity.vo.*;
import com.zdya.combatdocuments.service.DocumentService;
import com.zdya.combatdocuments.util.ResultVoUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

/**
 * @author bj
 * @date 23/6/1
 * @desc 文书库模块
 */
@RestController
@RequestMapping("/documents/document")
public class DocumentController {

    @Autowired
    private DocumentService documentService;

    /**
     *
     * @desc 查询文书列表
     * @param documentVO 接收前端参数实体
     * @return 文书列表
     */
    @GetMapping("/queryDocs")
    public TableDataInfo<Document> queryDocs(DocumentVO documentVO, PageQuery pageQuery) {
        Page<Document> documentPage = documentService.queryDocs(documentVO, pageQuery);
        return TableDataInfo.build(documentPage);
    }

    /**
     *
     * @desc 导出文件
     * @param ids id数组
     * @return
     */
    @GetMapping("/exprtDoc")
    public void exportDocs(@RequestParam("ids") Long[] ids, HttpServletResponse response) throws IOException {
        documentService.exportDocsByIds(ids, response);
    }

    /**
     * @desc 文书预览
     * @param id 文书id
     * @return
     */
    @GetMapping("/previewDoc")
    public ResultVo previewDoc(@RequestParam("id") Long id) {
        Map<String, String> map = documentService.previewDoc(id);
        return ResultVoUtil.success(map);
    }
}
